package com.tencent.sr.iris.activity.dependency.dto.common;

import com.alibaba.fastjson.JSONObject;
import com.tencent.sr.iris.activity.common.util.TimeUtils;
import com.tencent.sr.iris.activity.dependency.dto.group.*;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskSecondRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskThirdRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.GroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.group.GroupTaskSecondRequest;
import com.tencent.sr.iris.activity.interfaces.response.group.*;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * @author yuliu
 * @Date 2022/7/22 9:47
 */
public class GroupTaskBoardUtils {

    public static GroupTaskBoardResponse toGroupTaskBoardResponse(GroupTaskDTO groupTaskDTO) {
        GroupTaskBoardResponse groupTaskBoardResponse = new GroupTaskBoardResponse();
        groupTaskBoardResponse.setAuditStatus(groupTaskDTO.getAuditStatus());
        groupTaskBoardResponse.setAwardAmount(groupTaskDTO.getAwardAmount());
        groupTaskBoardResponse.setTaskPhaseJoinTime(groupTaskDTO.getTaskPhaseJoinTime());
        groupTaskBoardResponse.setPredictAwardAmount(groupTaskDTO.getPredictAwardAmount());
        groupTaskBoardResponse.setTaskUserJoinRecordId(groupTaskDTO.getTaskUserJoinRecordId());
        if (Objects.nonNull(groupTaskDTO.getTaskPhase())) {
            groupTaskBoardResponse.setTaskPhaseStatus(groupTaskDTO.getTaskPhase().getTaskPhaseStatus());
            groupTaskBoardResponse.setTaskTargetEvaluation(groupTaskDTO.getTaskPhase().getTaskTargetEvaluation());
            groupTaskBoardResponse.setTaskPhaseEndTime(groupTaskDTO.getTaskPhase().getTaskPhaseEndTime());
            groupTaskBoardResponse.setTaskPhaseStartTime(groupTaskDTO.getTaskPhase().getTaskPhaseStartTime());
            groupTaskBoardResponse.setTaskPhaseName(groupTaskDTO.getTaskPhase().getTaskPhaseName());
        }
        //排行榜新加
        groupTaskBoardResponse.setAwardType(groupTaskDTO.getAwardType());
        if (Objects.nonNull(groupTaskDTO.getRankAwardConfig())) {
            groupTaskBoardResponse.setCustomAwardName(groupTaskDTO.getRankAwardConfig().getCustomAwardName());
        }
        return groupTaskBoardResponse;
    }

    public static GroupTaskBoardSecondResponse toGroupTaskBoardSecondResponse(GroupTaskSecondDTO dto) {
        GroupTaskBoardSecondResponse secondResponse = new GroupTaskBoardSecondResponse();
        secondResponse.setIsValid(dto.getIsValid());
        secondResponse.setCommissionStatus(dto.getCommissionStatus());
        secondResponse.setOrderStatus(dto.getOrderStatus());
        secondResponse.setPlainOrderId(dto.getPlainOrderId());
        secondResponse.setThirdPartInviteUserDatetime(dto.getThirdPartInviteUserDatetime());
        secondResponse.setThirdPartOrderPrice(dto.getThirdPartOrderPrice());
        secondResponse.setValidGoodsNum(dto.getValidGoodsNum());
        secondResponse.setThirdPartOrderCreateTime(dto.getThirdPartOrderCreateTime());
        secondResponse.setNotValidReason(Optional.ofNullable(dto.getNotValidReason()).orElse(""));
        if (Objects.nonNull(dto.getTaskPhase())) {
            secondResponse.setTaskTargetEvaluation(dto.getTaskPhase().getTaskTargetEvaluation());
        }
        TaskWechatUserDTO taskWechatUser = dto.getTaskWechatUser();
        if (Objects.isNull(taskWechatUser)) {
            taskWechatUser = dto.getWechatUser();
        }
        if (Objects.isNull(taskWechatUser) && Objects.nonNull(dto.getTaskUserJoinRecord())) {
            TaskUserJoinRecordDTO joinRecord = dto.getTaskUserJoinRecord();
            taskWechatUser = Optional.ofNullable(joinRecord.getWechatUserDTO()).orElseGet(TaskWechatUserDTO::new);
        }
        taskWechatUser = Optional.ofNullable(taskWechatUser).orElseGet(TaskWechatUserDTO::new);
        secondResponse.setIrisUid(taskWechatUser.getIrisUid());
        secondResponse.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        secondResponse.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        secondResponse.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());
        //排行榜新加
        secondResponse.setIsInLeaderboard(dto.getIsInLeaderboard());
        secondResponse.setNotInLeaderboarReason(dto.getNotInLeaderboarReason());
        secondResponse.setOrderTime(dto.getOrderTime());
        secondResponse.setOrderEndStatus(dto.getOrderEndStatus());
        secondResponse.setOrderAmount(dto.getOrderAmount());
        secondResponse.setCategoryLevel3Id(dto.getCategoryLevel3Id());
        secondResponse.setUserPredictCommissionFee(dto.getUserPredictCommissionFee());
        secondResponse.setPredictCommissionFee(dto.getPredictCommissionFee());
        secondResponse.setUserLevelSnapshot(dto.getUserLevelSnapshot());

        //团推团
        secondResponse.setSumMonthValidCommissionBillCommissionFee(dto.getSumMonthValidCommissionBillCommissionFee());
        secondResponse.setSumValidCommissionBillCommissionFee(dto.getSumValidCommissionBillCommissionFee());
        secondResponse.setValidCommissionBillCommissionFee(dto.getValidCommissionBillCommissionFee());

        //特邀会员冲刺赛
        secondResponse.setThirdPartOrderUserLevel(dto.getThirdPartOrderUserLevel());
        secondResponse.setValidGmv(dto.getValidGmv());
        secondResponse.setCommissionBillCommissionFee(dto.getCommissionBillCommissionFee());
        if (Objects.nonNull(dto.getMCategoryLevel3Id())) {
            secondResponse.setCategoryLevel3Id(dto.getMCategoryLevel3Id());
        }
        return secondResponse;
    }

    public static GroupNormalTaskSecondResponse toGroupNormalTaskSecondResponse(GroupNormalTaskSecondDTO dto) {
        GroupNormalTaskSecondResponse response = new GroupNormalTaskSecondResponse();
        response.setPromoteStatus(dto.getPromoteStatus());
        response.setPromoteUserInviteDatetime(dto.getPromoteUserInviteDatetime());
        response.setPromoteStart(dto.getPromoteStart());
        response.setPromoteEnd(dto.getPromoteEnd());
        response.setPromoteGmv(dto.getPromoteGmv());
        response.setPredictCommissionFee(dto.getPredictCommissionFee());
        response.setSumPromoteGmv(dto.getSumPromoteGmv());
        response.setSumPredictCommissionFee(dto.getSumPredictCommissionFee());
        response.setSumMonthValidGmv(dto.getSumMonthValidGmv());

        TaskWechatUserDTO taskWechatUser = Optional.ofNullable(dto.getTaskWechatUserDTO())
                .orElseGet(TaskWechatUserDTO::new);
        response.setIrisUid(taskWechatUser.getIrisUid());
        response.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        response.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        response.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());

        UserBonusRuleSpecialStageNow userBonus = Optional.ofNullable(dto.getUserBonusRuleSpecialStageNow())
                .orElseGet(UserBonusRuleSpecialStageNow::new);
        response.setDayEnd(userBonus.getDayEnd());
        response.setDayStart(userBonus.getDayStart());

        response.setSumValidCommissionBillCommissionFee(dto.getSumValidCommissionBillCommissionFee());
        response.setSumMonthValidCommissionBillCommissionFee(dto.getSumMonthValidCommissionBillCommissionFee());
        response.setValidCommissionBillCommissionFee(dto.getValidCommissionBillCommissionFee());
        return response;
    }

    public static AdvisorNormalTaskSecondResponse toAdvisorNormalTaskSecondResponse(AdvisorBoardNormalSecondDTO dto) {
        AdvisorNormalTaskSecondResponse response = new AdvisorNormalTaskSecondResponse();
        response.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        response.setTaskPhaseJoinTime(dto.getTaskPhaseJoinTime());

        TaskWechatUserDTO taskWechatUser = Optional.ofNullable(dto.getTaskWechatUser())
                .orElseGet(TaskWechatUserDTO::new);
        response.setIrisUid(taskWechatUser.getIrisUid());
        response.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        response.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        response.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());
        response.setIrisUidLevel(taskWechatUser.getIrisUidLevel());

        response.setCountPromoteWechatUserNum(dto.getCountPromoteWechatUserNum());
        response.setCountPromoteSeniorWechatUserNum(dto.getCountPromoteSeniorWechatUserNum());
        response.setCountPromoteWechatUserNumContributing(dto.getCountPromoteWechatUserNumContributing());
        response.setCountPromoteSuperWechatUserNum(dto.getCountPromoteSuperWechatUserNum());

        TaskPhaseBonusRuleDTO taskPhaseBonusRuleDTO = Optional.ofNullable(dto.getTaskPhaseBonusRule())
                .orElseGet(TaskPhaseBonusRuleDTO::new);
        response.setBonusRuleStage(taskPhaseBonusRuleDTO.getBonusRuleStage());
        response.setCommissionTimes(taskPhaseBonusRuleDTO.getCommissionTimes());

        response.setSumMonthAwardAmount(dto.getSumMonthAwardAmount());
        response.setSumMonthValidGmv(dto.getSumMonthValidGmv());
        response.setAreaId(dto.getAreaId());
        response.setSumValidGmv(dto.getSumValidGmv());
        response.setSumPromoteCommissionFee(dto.getSumPromoteCommissionFee());
        response.setSumMonthPredictAwardAmount(dto.getSumMonthPredictAwardAmount());

        response.setSumMonthValidCommissionBillCommissionFee(dto.getSumMonthValidCommissionBillCommissionFee());
        response.setSumValidCommissionBillCommissionFee(dto.getSumValidCommissionBillCommissionFee());
        return response;
    }

    public static AdvisorBoardCommissionThirdResponse toAdvisorBoardCommissionThirdResponse(
            AdvisorBoardCommissionThirdDTO dto) {
        AdvisorBoardCommissionThirdResponse response = new AdvisorBoardCommissionThirdResponse();
        response.setCommissionStatus(dto.getCommissionStatus());
        response.setOrderStatus(dto.getOrderStatus());
        response.setPlainOrderId(dto.getPlainOrderId());
        response.setThirdPartOrderPrice(dto.getThirdPartOrderPrice());

        response.setCommissionFee(dto.getCommissionFee());
        response.setPredictCommissionFee(dto.getPredictCommissionFee());
        response.setCompensateCommissionFee(dto.getCompensateCommissionFee());
        response.setPredictCompensateCommissionFee(dto.getPredictCompensateCommissionFee());
        response.setPredictCommissionTotalFee(dto.getPredictCommissionTotalFee());

        response.setCompensateCommissionProvideStatus(dto.getCompensateCommissionProvideStatus());
        response.setThirdPartOrderCreateTime(dto.getThirdPartOrderCreateTime());

        TaskWechatUserDTO taskWechatUser = Optional.ofNullable(dto.getTaskWechatUser())
                .orElseGet(TaskWechatUserDTO::new);
        response.setIrisUid(taskWechatUser.getIrisUid());
        response.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        response.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        response.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());

        return response;
    }

    public static AdvisorBoardResponse toAdvisorBoardResponse(AdvisorBoardDTO dto) {
        AdvisorBoardResponse boardResponse = new AdvisorBoardResponse();
        boardResponse.setTaskPhaseName(dto.getTaskPhaseName());
        boardResponse.setTaskPhaseId(dto.getTaskPhaseId());
        boardResponse.setTaskPhaseStartTime(dto.getTaskPhaseStartTime());
        boardResponse.setTaskPhaseEndTime(dto.getTaskPhaseEndTime());
        boardResponse.setTaskPhaseStatus(dto.getTaskPhaseStatus());
        boardResponse.setTaskTargetEvaluation(dto.getTaskTargetEvaluation());
        boardResponse.setTaskPhaseLeaderLimit(dto.getTaskPhaseLeaderLimit());
        boardResponse.setTaskPhaseLeaderJoinCount(dto.getTaskPhaseLeaderJoinCount());
        boardResponse.setCountPredictAwardUserNum(dto.getCountPredictAwardUserNum());
        boardResponse.setSumPredictAwardAmount(dto.getSumPredictAwardAmount());
        boardResponse.setSumAwardAmount(dto.getSumAwardAmount());
        return boardResponse;
    }

    public static AdvisorBoardInviteSecondResponse toAdvisorBoardInviteSecondResponse(AdvisorBoardInviteSecondDTO dto) {
        AdvisorBoardInviteSecondResponse inviteSecondResponse = new AdvisorBoardInviteSecondResponse();
        inviteSecondResponse.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        inviteSecondResponse.setAuditStatus(dto.getAuditStatus());
        inviteSecondResponse.setAwardAmount(dto.getAwardAmount());
        if (Objects.nonNull(dto.getTaskPhase())) {
            inviteSecondResponse.setTaskTargetEvaluation(dto.getTaskPhase().getTaskTargetEvaluation());
        }
        if (Objects.nonNull(dto.getTaskPhaseBonusRule())) {
            inviteSecondResponse.setBonusRuleStage(dto.getTaskPhaseBonusRule().getBonusRuleStage());
            inviteSecondResponse.setCommissionTimes(dto.getTaskPhaseBonusRule().getCommissionTimes());
        } else {
            inviteSecondResponse.setBonusRuleStage(0);
        }
        inviteSecondResponse.setPredictAwardAmount(dto.getPredictAwardAmount());
        inviteSecondResponse.setTaskPhaseJoinTime(dto.getTaskPhaseJoinTime());
        inviteSecondResponse.setTotalInviteUserNum(dto.getTotalInviteUserNum());
        inviteSecondResponse.setValidInviteUserNum(dto.getValidInviteUserNum());
        if (Objects.nonNull(dto.getTaskWechatUser())) {
            inviteSecondResponse.setWechatUserHeadimgurl(dto.getTaskWechatUser().getWechatUserHeadimgurl());
            inviteSecondResponse.setWechatUserNickname(dto.getTaskWechatUser().getWechatUserNickname());
            inviteSecondResponse.setWechatUserUnionid(dto.getTaskWechatUser().getWechatUserUnionid());
            inviteSecondResponse.setIrisUid(dto.getTaskWechatUser().getIrisUid());
            inviteSecondResponse.setIrisUidLevel(dto.getTaskWechatUser().getIrisUidLevel());
        }
        return inviteSecondResponse;
    }

    public static AdvisorBoardFirstOrderSecondResponse toAdvisorBoardFirstOrderSecondResponse(
            AdvisorBoardFirstOrderSecondDTO dto) {
        AdvisorBoardFirstOrderSecondResponse response = new AdvisorBoardFirstOrderSecondResponse();
        response.setAuditStatus(dto.getAuditStatus());
        response.setAwardAmount(dto.getAwardAmount());
        response.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        if (Objects.nonNull(dto.getTaskPhaseBonusRule())) {
            response.setBonusRuleStage(dto.getTaskPhaseBonusRule().getBonusRuleStage());
            response.setCommissionTimes(dto.getTaskPhaseBonusRule().getCommissionTimes());
        } else {
            response.setBonusRuleStage(0);
        }
        if (Objects.nonNull(dto.getTaskPhase())) {
            response.setTaskTargetEvaluation(dto.getTaskPhase().getTaskTargetEvaluation());
        }
        response.setTaskPhaseJoinTime(dto.getTaskPhaseJoinTime());
        response.setPredictAwardAmount(dto.getPredictAwardAmount());
        response.setValidInviteUserNum(dto.getValidInviteUserNum());
        response.setTotalInviteUserNum(dto.getTotalInviteUserNum());
        if (Objects.nonNull(dto.getTaskWechatUser())) {
            response.setWechatUserNickname(dto.getTaskWechatUser().getWechatUserNickname());
            response.setWechatUserHeadimgurl(dto.getTaskWechatUser().getWechatUserHeadimgurl());
            response.setIrisUid(dto.getTaskWechatUser().getIrisUid());
            response.setWechatUserUnionid(dto.getTaskWechatUser().getWechatUserUnionid());
            response.setIrisUidLevel(dto.getTaskWechatUser().getIrisUidLevel());
        }
        return response;
    }

    public static AdvisorBoardSprintSecondResponse toAdvisorBoardSprintSecondResponse(AdvisorBoardSprintSecondDTO dto) {
        AdvisorBoardSprintSecondResponse sprintSecondResponse = new AdvisorBoardSprintSecondResponse();
        sprintSecondResponse.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        sprintSecondResponse.setAuditStatus(dto.getAuditStatus());
        sprintSecondResponse.setAwardAmount(dto.getAwardAmount());
        sprintSecondResponse.setPredictAwardAmount(dto.getPredictAwardAmount());
        sprintSecondResponse.setTaskPhaseJoinTime(dto.getTaskPhaseJoinTime());
        sprintSecondResponse.setValidGmv(dto.getValidGmv());
        sprintSecondResponse.setValidGoodsNum(dto.getValidGoodsNum());
        sprintSecondResponse.setValidOrderNum(dto.getValidOrderNum());
        sprintSecondResponse.setValidCommissionBillCommissionFee(dto.getValidCommissionBillCommissionFee());
        sprintSecondResponse.setValidInviteUserNum(dto.getValidInviteUserNum());
        if (Objects.nonNull(dto.getTaskPhase())) {
            sprintSecondResponse.setTaskTargetEvaluation(dto.getTaskPhase().getTaskTargetEvaluation());
        }
        if (Objects.nonNull(dto.getTaskPhaseBonusRule())) {
            sprintSecondResponse.setBonusRuleStage(dto.getTaskPhaseBonusRule().getBonusRuleStage());
            sprintSecondResponse.setCommissionTimes(dto.getTaskPhaseBonusRule().getCommissionTimes());
        } else {
            sprintSecondResponse.setBonusRuleStage(0);
        }
        if (Objects.nonNull(dto.getTaskWechatUser())) {
            sprintSecondResponse.setIrisUidLevel(dto.getTaskWechatUser().getIrisUidLevel());
            sprintSecondResponse.setIrisUid(dto.getTaskWechatUser().getIrisUid());
            sprintSecondResponse.setWechatUserHeadimgurl(dto.getTaskWechatUser().getWechatUserHeadimgurl());
            sprintSecondResponse.setWechatUserNickname(dto.getTaskWechatUser().getWechatUserNickname());
            sprintSecondResponse.setWechatUserUnionid(dto.getTaskWechatUser().getWechatUserUnionid());
        }
        return sprintSecondResponse;
    }

    public static AdvisorBoardCommissionSecondResponse toAdvisorBoardCommissionSecondResponse(
            AdvisorBoardCommissionSecondDTO dto) {
        AdvisorBoardCommissionSecondResponse response = new AdvisorBoardCommissionSecondResponse();
        response.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        response.setAwardAmount(dto.getAwardAmount());
        response.setPredictAwardAmount(dto.getPredictAwardAmount());
        response.setAuditStatus(dto.getAuditStatus());

        TaskPhaseDTO taskPhase = Optional.ofNullable(dto.getTaskPhase()).orElseGet(TaskPhaseDTO::new);
        response.setTaskPhaseStartTime(taskPhase.getTaskPhaseStartTime());
        response.setTaskPhaseStatus(taskPhase.getTaskPhaseStatus());

        response.setValidOrderNum(dto.getValidOrderNum());
        response.setPredictValidOrderNum(dto.getPredictValidOrderNum());

        TaskWechatUserDTO taskWechatUser = Optional.ofNullable(dto.getTaskWechatUser())
                .orElseGet(TaskWechatUserDTO::new);
        response.setIrisUid(taskWechatUser.getIrisUid());
        response.setIrisUidLevel(taskWechatUser.getIrisUidLevel());
        response.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());
        response.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        response.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        return response;
    }

    public static AdvisorBoardRankSecondResponse toAdvisorBoardRankSecondResponse(AdvisorBoardRankSecondDTO dto) {
        AdvisorBoardRankSecondResponse response = new AdvisorBoardRankSecondResponse();
        response.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        TaskWechatUserDTO taskWechatUser = Optional.ofNullable(dto.getTaskWechatUser())
                .orElseGet(TaskWechatUserDTO::new);
        response.setIrisUid(taskWechatUser.getIrisUid());
        response.setIrisUidLevel(taskWechatUser.getIrisUidLevel());
        response.setWechatUserUnionid(taskWechatUser.getWechatUserUnionid());
        response.setWechatUserNickname(taskWechatUser.getWechatUserNickname());
        response.setWechatUserHeadimgurl(taskWechatUser.getWechatUserHeadimgurl());
        response.setAwardType(dto.getAwardType());
        response.setAuditStatus(dto.getAuditStatus());
        response.setAwardAmount(dto.getAwardAmount());
        response.setValidGmv(dto.getValidGmv());
        response.setPredictAwardAmount(dto.getPredictAwardAmount());
        response.setValidOrderNum(dto.getValidOrderNum());
        response.setRankNum(dto.getRankNum());
        response.setValidCommissionBillCommissionFee(dto.getValidCommissionBillCommissionFee());
        RankAwardConfigDTO rankAwardConfigDTO = Optional.ofNullable(dto.getRankAwardConfig())
                .orElseGet(RankAwardConfigDTO::new);
        response.setCustomAwardName(rankAwardConfigDTO.getCustomAwardName());
        if (Objects.nonNull(rankAwardConfigDTO.getRankingStart())
                && Objects.nonNull(rankAwardConfigDTO.getRankingEnd())) {
            if (rankAwardConfigDTO.getRankingStart().equals(rankAwardConfigDTO.getRankingEnd())) {
                response.setRankRang(rankAwardConfigDTO.getRankingStart().toString());
            } else {
                response.setRankRang(rankAwardConfigDTO.getRankingStart() + "-" + rankAwardConfigDTO.getRankingEnd());
            }
        }
        return response;
    }

    public static AdvisorBoardSecondResponse toAdvisorBoardSecondResponse(AdvisorBoardSecondDTO dto) {
        AdvisorBoardSecondResponse response = new AdvisorBoardSecondResponse();
        response.setAuditStatus(dto.getAuditStatus());
        response.setAwardAmount(dto.getAwardAmount());
        response.setTaskUserJoinRecordId(dto.getTaskUserJoinRecordId());
        if (Objects.nonNull(dto.getTaskPhaseBonusRule())) {
            response.setBonusRuleStage(dto.getTaskPhaseBonusRule().getBonusRuleStage());
            response.setCommissionTimes(dto.getTaskPhaseBonusRule().getCommissionTimes());
        } else {
            response.setBonusRuleStage(0);
        }
        if (Objects.nonNull(dto.getTaskPhase())) {
            response.setTaskTargetEvaluation(dto.getTaskPhase().getTaskTargetEvaluation());
        }
        response.setTaskPhaseJoinTime(dto.getTaskPhaseJoinTime());
        response.setPredictAwardAmount(dto.getPredictAwardAmount());
        response.setValidInviteUserNum(dto.getValidInviteUserNum());
        response.setTotalInviteUserNum(dto.getTotalInviteUserNum());
        response.setPredictValidOrderNum(dto.getPredictValidOrderNum());
        response.setValidOrderNum(dto.getValidOrderNum());

        TaskPhaseDTO taskPhase = Optional.ofNullable(dto.getTaskPhase()).orElseGet(TaskPhaseDTO::new);
        response.setTaskPhaseStartTime(taskPhase.getTaskPhaseStartTime());
        response.setTaskPhaseStatus(taskPhase.getTaskPhaseStatus());

        response.setValidGmv(dto.getValidGmv());
        response.setValidGoodsNum(dto.getValidGoodsNum());

        response.setAreaId(dto.getAreaId());
        if (Objects.nonNull(dto.getTaskWechatUser())) {
            response.setWechatUserNickname(dto.getTaskWechatUser().getWechatUserNickname());
            response.setWechatUserHeadimgurl(dto.getTaskWechatUser().getWechatUserHeadimgurl());
            response.setIrisUid(dto.getTaskWechatUser().getIrisUid());
            response.setWechatUserUnionid(dto.getTaskWechatUser().getWechatUserUnionid());
            response.setIrisUidLevel(dto.getTaskWechatUser().getIrisUidLevel());
        }

        response.setCountPromoteWechatUserNum(dto.getCountPromoteWechatUserNum());
        response.setCountPromoteSeniorWechatUserNum(dto.getCountPromoteSeniorWechatUserNum());
        response.setCountPromoteSuperWechatUserNum(dto.getCountPromoteSuperWechatUserNum());
        response.setCountPromoteWechatUserNumContributing(dto.getCountPromoteWechatUserNumContributing());
        response.setSumMonthPredictAwardAmount(dto.getSumMonthPredictAwardAmount());
        response.setSumPromoteCommissionFee(dto.getSumPromoteCommissionFee());
        response.setSumMonthAwardAmount(dto.getSumMonthAwardAmount());
        response.setSumMonthValidGmv(dto.getSumMonthValidGmv());
        response.setSumValidGmv(dto.getSumValidGmv());

        //排行榜
        response.setAwardType(dto.getAwardType());
        response.setRankNum(dto.getRankNum());
        response.setValidCommissionBillCommissionFee(dto.getValidCommissionBillCommissionFee());
        RankAwardConfigDTO rankAwardConfigDTO = Optional.ofNullable(dto.getRankAwardConfig())
                .orElseGet(RankAwardConfigDTO::new);
        response.setCustomAwardName(rankAwardConfigDTO.getCustomAwardName());
        if (Objects.nonNull(rankAwardConfigDTO.getRankingStart())
                && Objects.nonNull(rankAwardConfigDTO.getRankingEnd())) {
            if (rankAwardConfigDTO.getRankingStart().equals(rankAwardConfigDTO.getRankingEnd())) {
                response.setRankRang(rankAwardConfigDTO.getRankingStart().toString());
            } else {
                response.setRankRang(rankAwardConfigDTO.getRankingStart() + "-" + rankAwardConfigDTO.getRankingEnd());
            }
        }

        //团推团
        response.setSumMonthValidCommissionBillCommissionFee(dto.getSumMonthValidCommissionBillCommissionFee());
        response.setSumValidCommissionBillCommissionFee(dto.getSumValidCommissionBillCommissionFee());

        response.setAdvisorUid(dto.getAdvisorUid());

        //特邀会员冲刺赛
        response.setUserLevel(dto.getUserLevel());
        response.setStageNum(dto.getStageNum());
        response.setTaskUserCyclePerformanceId(dto.getTaskUserCyclePerformanceId());
        TaskUserJoinRecordDTO taskUserJoinRecordDTO = dto.getTaskUserJoinRecordDTO();
        if (Objects.nonNull(taskUserJoinRecordDTO)) {
            response.setAdvisorUid(taskUserJoinRecordDTO.getAdvisorUid());
            response.setAreaId(taskUserJoinRecordDTO.getArea());
            response.setTaskPhaseJoinTime(taskUserJoinRecordDTO.getTaskPhaseJoinTime());
            response.setTotalAwardAmount(taskUserJoinRecordDTO.getAwardAmount());
            response.setTotalValidCommissionBillCommissionFee(
                    taskUserJoinRecordDTO.getValidCommissionBillCommissionFee());
            response.setTotalValidGmv(taskUserJoinRecordDTO.getValidGmv());
            response.setPredictAwardAmount(taskUserJoinRecordDTO.getPredictAwardAmount());
        }
        return response;
    }

    public static <REQ> JSONObject toJsonString(PaginationRequest<REQ> request) {
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(request.getQueryCriteria());
        jsonObject.put("page", request.getPageNum());
        jsonObject.put("per_page", request.getPageSize());
        return jsonObject;
    }

    public static String toGroupTaskBoardBody(PaginationRequest<GroupTaskRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("task_phase_start_time", timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("task_phase_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));
        jsonObject.put("task_phase_join_start_time",
                timestampToTime(request.getQueryCriteria().getTaskPhaseJoinStartTime()));
        jsonObject
                .put("task_phase_join_end_time", timestampToTime(request.getQueryCriteria().getTaskPhaseJoinEndTime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toGroupTaskSecondBoardBody(PaginationRequest<GroupTaskSecondRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("third_part_order_create_start_time",
                timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("third_part_order_create_end_time",
                timestampToTime(request.getQueryCriteria().getEndTime()));
        jsonObject.put("promote_user_invite_start_datetime",
                timestampToTime(request.getQueryCriteria().getPromoteUserInviteStartDatetime()));
        jsonObject.put("promote_user_invite_end_datetime",
                timestampToTime(request.getQueryCriteria().getPromoteUserInviteEndDatetime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toAdvisorBoardBody(PaginationRequest<AdvisorGroupTaskRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("task_phase_start_time", timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("task_phase_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toAdvisorSecondBoardInviteBody(PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("task_phase_start_time", timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("task_phase_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toAdvisorSecondBoardSprintBody(PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("task_phase_start_time", timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("task_phase_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toAdvisorSecondBoardCommissionBody(PaginationRequest<AdvisorGroupTaskSecondRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("task_phase_join_start_time",
                timestampToTime(request.getQueryCriteria().getTaskPhaseJoinStartTime()));
        jsonObject
                .put("task_phase_join_end_time", timestampToTime(request.getQueryCriteria().getTaskPhaseJoinEndTime()));

        jsonObject.put("task_phase_start_time", timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("task_phase_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));

        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String toAdvisorThirdBoardBody(PaginationRequest<AdvisorGroupTaskThirdRequest> request) {
        JSONObject jsonObject = toJsonString(request);
        jsonObject.put("third_part_order_create_start_time",
                timestampToTime(request.getQueryCriteria().getStartTime()));
        jsonObject.put("third_part_order_create_end_time", timestampToTime(request.getQueryCriteria().getEndTime()));
        jsonObject.put("promote_user_invite_start_datetime",
                timestampToTime(request.getQueryCriteria().getPromoteUserInviteStartDatetime()));
        jsonObject.put("promote_user_invite_end_datetime",
                timestampToTime(request.getQueryCriteria().getPromoteUserInviteEndDatetime()));
        String reqBody = jsonObject.toJSONString();
        return reqBody;
    }

    public static String timestampToTime(String timestamp) {
        if (StringUtils.isEmpty(timestamp)) {
            return null;
        }
        Date date = new Date(Long.parseLong(timestamp));
        return TimeUtils.parse(date, TimeUtils.YYYY_MM_DD_HH_MM_SS);
    }

}
